#!/bin/bash

dl_path='/dl/nginx'
install_path='/basic/nginx'
link_dir='/usr/exec'
version='1.21.6'

dep() {
  yum -y install zlib zlib-devel gcc-c++ libtool openssl openssl-devel git
}

dir() {
  mkdir -p $dl_path
  mkdir -p $install_path
}

self() {
  cd $dl_path || exit
  wget http://nginx.org/download/nginx-"$version".tar.gz
  tar -zxvf nginx-"$version".tar.gz

  cd nginx-"$version" || exit
  ./configure --prefix=$install_path --with-http_stub_status_module --with-http_ssl_module
  make && make install

  mkdir $link_dir
  ln -s ${install_path}/sbin/nginx /bin/nginx
  nginx -v

  firewall-cmd --zone=public --add-port=80/tcp --permanent
  firewall-cmd --reload
}

self_boot() {
  cat <<'EOF' >>/etc/rc.local

/basic/nginx/sbin/nginx
EOF
}

dep
dir
module
self
